<?php
Junction_FileCabinet::using("Junction_Db_Common_ResultSet");
Junction_FileCabinet::using("Junction_Core_Mapping");

class Junction_Core_Iterator implements Iterator {
	
	/**
	 * Result set
	 *
	 * @var Iterator
	 */
	private $_data;
	
	/**
	 * Mapping between object and table
	 *
	 * @var Junction_Core_Mapping
	 */
	private $_mapping;
	
	public function __construct(Junction_Db_Common_ResultSet $results, Junction_Core_Mapping $map) {
		$this->_data = $results->getIterator();
		$this->_mapping = $map;
	}
	
	/**
	 * Move the iterator's pointer to the next element.
	 *
	 */
	public function next() {
		$this->_data->next();
	}
	
	/**
	 * Retrieve the current element being pointed to.
	 *
	 * @return Object an instance of the client's object
	 */
	public function current() {
		return $this->_mapping->push($this->_data->current());
	}
	
	/**
	 * Retrieve the current pointer.
	 *
	 * @return unknown
	 */
	public function key() {
		return $this->_data->key();
	}
	
	/**
	 * Reset the iterator.
	 *
	 */
	public function rewind() {
		$this->_data->rewind();
	}
	
	/**
	 * Return whether the current value is valid.
	 * 
	 * @return boolean
	 */
	public function valid() {
		return $this->_data->valid();
	}
}
?>